// 接收创建的 action
import { handleActions } from 'redux-actions'

import {
	register,
	register_success,
	register_fail,
	register_reset
} from '../actions/register'

const initialState = {
	// 正在加载
	loading: false,
	loaded: false,
	success: false,
	message: ''
}

const registerReducer = handleActions ({
	[register]: () => ({
		loading: true,
		loaded: false,
		success: false,
		message: ''
	}), 
	[register_success]: () => ({
		loading: false,
		loaded: true,
		success: true,
		message: ''
	}),
	[register_fail]: (state, action) => ({
		loading: false,
		loaded: true,
		success: false,
		message: action.payload.message
	}),
	[register_reset]: ()=> ({
		loading: false,
		loaded: false,
		success: false,
		message: ''
	})
},initialState)

export default registerReducer